import { createApp, App as AppInstance } from 'vue'
import App from './App.vue'
import Vant from 'vant'
import 'vant/lib/index.css'
import Router from './router'
import Store, { key } from './store'
import './styles/index.less'
import directives from './directives'
import 'amfe-flexible'
import XEUtils from 'xe-utils'
import dayjs from 'dayjs'
import relativeTime from 'dayjs/plugin/relativeTime'
import { setAxiosInstance } from '@evaluation-common/api'
import axiosInstance from './api/axios'

console.log(111)

import {
  // 核心
  VXETable,
  // 表格功能
  Header,
  // 可选组件
  Column,
  Table,
} from 'vxe-table'
import zhCN from 'vxe-table/es/locale/lang/zh-CN'

// 按需加载的方式默认是不带国际化的，自定义国际化需要自行解析占位符 '{0}'，例如：
VXETable.setup({
  i18n: (key, args) => XEUtils.toFormatString(XEUtils.get(zhCN, key), args),
})

function useTable(app: AppInstance) {
  // 表格功能
  app
    .use(Header)
    .use(Column)
    // 安装表格
    .use(Table)

  // 给 vue 实例挂载内部对象，例如：
  // app.config.globalProperties.$XModal = VXETable.modal
  // app.config.globalProperties.$XPrint = VXETable.print
  // app.config.globalProperties.$XSaveFile = VXETable.saveFile
  // app.config.globalProperties.$XReadFile = VXETable.readFile
}

setAxiosInstance(axiosInstance)

dayjs.extend(relativeTime)

const app = createApp(App)

directives(app)

app.use(Vant)
app.use(useTable)
app.use(Router)
app.use(Store, key)

app.mount('#app')
